package com.xinghen.ace.auth.util;

import com.xinghen.ace.auth.common.jwt.IJWTInfo;
import com.xinghen.ace.auth.common.jwt.JWTHelper;
import com.xinghen.ace.auth.configuration.KeyConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @author xinghen
 * @ClassName: ClientTokenUtil
 * @Package: com.xinghen.ace.auth.util
 * @Description client token 工具
 * @create 2018/5/4 15:39
 */
@Configuration
public class ClientTokenUtil {

    @Value("${client.expire}")
    private int expire;
    @Autowired
    private KeyConfiguration keyConfiguration;

    public String generateToken(IJWTInfo jwtInfo) throws Exception {
        return JWTHelper.generateToken(jwtInfo, keyConfiguration.getServicePriKey(), expire);
    }

    public IJWTInfo getInfoFromToken(String token) throws Exception {
        return JWTHelper.getInfoFromToken(token, keyConfiguration.getServicePubKey());
    }

}
